#pragma once
#include "Wincrypt.h"

enum CCryptKeyType
{
	CCRYPT_RSA=CALG_RSA_SIGN,
	CCRYPT_DES=CALG_3DES,
};

enum CCryptHashType
{
	CCRYPT_SHA1=CALG_SHA1,
};

class CCryptKey
{
public:
	CCryptKey();
	~CCryptKey(){}
	BOOL InitProv(LPCSTR Container,DWORD KeyType);
	void ReleaseProv();
	BOOL GetKey(string& KeyBlob,DWORD WParam=0,DWORD LParam=0);
	BOOL ImportKey(string& KeyBlob,DWORD WParam=0,DWORD LParam=0);
public:
	CStringA m_Container;
	DWORD m_KeyType;
	HCRYPTPROV m_Prov;
	HCRYPTKEY m_Key;
};

class CCrypt
{
public:
	CCrypt(void);
	~CCrypt(void);
	static CCrypt* GetInstance();
	BOOL GenKey(CCryptKey* Key,DWORD WParam=0,DWORD LParam=0);
	BOOL SignHash(CCryptKey* Key,DWORD WParam=0,DWORD LParam=0);
	BOOL VerifyData(CCryptKey* Key,DWORD WParam=0,DWORD LParam=0);
	BOOL CalHash(DWORD HashType,string& HashData);
private:
	BOOL CalHash(CCryptKey* Key,DWORD HashType,string& HashData);
};
